class Solution {
public:
    using LL = long long;
    long long repairCars(vector<int>& ranks, int cars) {
        long long r = 1e14, l = 0;
        auto check = [&](LL x) {
            long long ans = 0;
            for (auto y : ranks) {
                int cnt = sqrt(x / y);
                ans += cnt;
            }
            return ans >= cars;
        };
        while (l + 1 < r) {
            long long mid = l + r >> 1;
            if (check(mid))r = mid;
            else l = mid;
        }
        return r;
    }
};